package cn.com.sparkle.paxos.event;

import java.util.LinkedList;

import org.apache.log4j.Logger;

public class EventDispatcher {
	private final static Logger logger = Logger
			.getLogger(EventDispatcher.class);
	private LinkedList<Event> events = new LinkedList<Event>();

	public void register(Event event) {
		events.add(event);
	}

	public void unRegister(Event event) {
		events.remove(event);
	}

	public void doAllEvent(Object... args) {
		for (Event e : events) {
			try {
				e.event(args);
			} catch (Throwable throwable) {
				logger.error("unexcepted exception", throwable);
			}
		}
	}
}
